package com.project.erp.model.fobcost;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.struts2.json.annotations.JSON;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import com.google.common.collect.Lists;
import com.project.erp.model.IdEntity;
import com.project.erp.model.contract.trade.TradeCusContract;

/**
 * FOB成本主表
 * 
 * 使用JPA annotation定义ORM关系. 使用Hibernate annotation定义JPA 1.0未覆盖的部分.
 * 
 * @author lijiaguo
 * @date 2013-10-18 22:09
 */
@Entity
// 表名与类名不相同时重新定义表名.
@Table(name = "TBL_FOB_COST")
// 默认的缓存策略.
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class FobCost extends IdEntity {
	/**
	 * 
	 */
	private static final long serialVersionUID = 6225883152086912774L;

	private String item; //FOB项目
	private String fobSize; //规格
	private Double facDeliPrice; //单价工厂交货价
	private Double trailerCharge;//拖车费
	private Double dockDeliPrice; //码头交货价
	private Double fobFee; //FOB费用
	private Double fobPriceRmb; //FOB单价(人民币)
	private Double fobPriceUsd; //FOB单价(美元)
	private Double fobOneRmb; //FOB+1
	private Double fobOneUsd; //FOB+1
	private Double mperCtainer; //平方/柜
	private Double boxPerCtainer; //箱数/柜
	private Double fobFeeCtainer; //FOB费用/柜
	private Long containers;//柜数
	private Boolean isTemplate;//是否为模板 "1"是,"0"不是 在生成客户合同时用到
	private String createUser; //创建用户
	private Date createTime; //创建时间
	private String updateUser; //更新用户
	private Date updateTime; //更新时间
	
	private List<TradeCusContract> tradeCusContracts = Lists.newArrayList();//与外贸客户表关联
	
	private Date startTime;	//创建开始时间--用于查询
	private Date endTime;		//创建结束时间--用于查询
	
	public FobCost() {
	}

	public FobCost(String item, String fobSize, Double facDeliPrice,
			Double dockDeliPrice, Double fobFee, Double fobPriceRmb,
			Double fobPriceUsd, Double fobOneRmb, Double fobOneUsd,
			Double mperCtainer, Double boxPerCtainer, Double fobFeeCtainer,
			Boolean isTemplate, String createUser, Date createTime,
			String updateUser, Date updateTime, Date startTime, Date endTime,
			List<FobCostDetail> fobCostList) {
		super();
		this.item = item;
		this.fobSize = fobSize;
		this.facDeliPrice = facDeliPrice;
		this.dockDeliPrice = dockDeliPrice;
		this.fobFee = fobFee;
		this.fobPriceRmb = fobPriceRmb;
		this.fobPriceUsd = fobPriceUsd;
		this.fobOneRmb = fobOneRmb;
		this.fobOneUsd = fobOneUsd;
		this.mperCtainer = mperCtainer;
		this.boxPerCtainer = boxPerCtainer;
		this.fobFeeCtainer = fobFeeCtainer;
		this.isTemplate = isTemplate;
		this.createUser = createUser;
		this.createTime = createTime;
		this.updateUser = updateUser;
		this.updateTime = updateTime;
		this.startTime = startTime;
		this.endTime = endTime;
		this.fobCostList = fobCostList;
	}



	//主表关联细表
	private List<FobCostDetail> fobCostList = Lists.newArrayList(); //有序的关联对象集合
	
	//字段非空且唯一, 用于提醒Entity使用者及生成DDL.
	@Column(nullable = false)
	public String getItem() {
		return item;
	}

	public void setItem(String item) {
		this.item = item;
	}

	public String getFobSize() {
		return fobSize;
	}

	public void setFobSize(String fobSize) {
		this.fobSize = fobSize;
	}

	public Double getFacDeliPrice() {
		return facDeliPrice;
	}

	public void setFacDeliPrice(Double facDeliPrice) {
		this.facDeliPrice = facDeliPrice;
	}

	public Double getDockDeliPrice() {
		return dockDeliPrice;
	}

	public void setDockDeliPrice(Double dockDeliPrice) {
		this.dockDeliPrice = dockDeliPrice;
	}

	public Double getFobFee() {
		return fobFee;
	}

	public void setFobFee(Double fobFee) {
		this.fobFee = fobFee;
	}

	public Double getFobPriceRmb() {
		return fobPriceRmb;
	}

	public void setFobPriceRmb(Double fobPriceRmb) {
		this.fobPriceRmb = fobPriceRmb;
	}

	public Double getFobPriceUsd() {
		return fobPriceUsd;
	}

	public void setFobPriceUsd(Double fobPriceUsd) {
		this.fobPriceUsd = fobPriceUsd;
	}

	public Double getFobOneRmb() {
		return fobOneRmb;
	}

	public void setFobOneRmb(Double fobOneRmb) {
		this.fobOneRmb = fobOneRmb;
	}

	public Double getFobOneUsd() {
		return fobOneUsd;
	}

	public void setFobOneUsd(Double fobOneUsd) {
		this.fobOneUsd = fobOneUsd;
	}

	public Double getMperCtainer() {
		return mperCtainer;
	}

	public void setMperCtainer(Double mperCtainer) {
		this.mperCtainer = mperCtainer;
	}

	public Double getBoxPerCtainer() {
		return boxPerCtainer;
	}

	public void setBoxPerCtainer(Double boxPerCtainer) {
		this.boxPerCtainer = boxPerCtainer;
	}

	public Double getFobFeeCtainer() {
		return fobFeeCtainer;
	}

	public void setFobFeeCtainer(Double fobFeeCtainer) {
		this.fobFeeCtainer = fobFeeCtainer;
	}

	public String getCreateUser() {
		return createUser;
	}

	public Boolean getIsTemplate() {
		return isTemplate;
	}

	public void setIsTemplate(Boolean isTemplate) {
		this.isTemplate = isTemplate;
	}

	public void setCreateUser(String createUser) {
		this.createUser = createUser;
	}

	public String getUpdateUser() {
		return updateUser;
	}

	public void setUpdateUser(String updateUser) {
		this.updateUser = updateUser;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}

	//mappedBy="expenses"说明此字段由实体ExpensesDetail的字段expenses映射而来，防止生成关联表
	@OneToMany(mappedBy="fobCost")
	@Cascade(value = {CascadeType.SAVE_UPDATE,CascadeType.DELETE,CascadeType.ALL}) 
	public List<FobCostDetail> getFobCostList() {
		return fobCostList;
	}

	public void setFobCostList(List<FobCostDetail> fobCostList) {
		this.fobCostList = fobCostList;
	}

	@Transient
	@JSON(format="yyyy-MM-dd")
	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	@Transient
	@JSON(format="yyyy-MM-dd")
	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	@JSON(format="yyyy-MM-dd")
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@JSON(format="yyyy-MM-dd")
	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	public Long getContainers() {
		return containers;
	}

	public void setContainers(Long containers) {
		this.containers = containers;
	}

	public Double getTrailerCharge() {
		return trailerCharge;
	}

	public void setTrailerCharge(Double trailerCharge) {
		this.trailerCharge = trailerCharge;
	}

	@ManyToMany(mappedBy="fobCostList",cascade=javax.persistence.CascadeType.REFRESH) 
	public List<TradeCusContract> getTradeCusContracts() {
		return tradeCusContracts;
	}

	public void setTradeCusContracts(List<TradeCusContract> tradeCusContracts) {
		this.tradeCusContracts = tradeCusContracts;
	}
	
	
}
